from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.image import Image
from kivy.uix.gridlayout import GridLayout
from kivy.uix.screenmanager import Screen, ScreenManager
people_list = ['a','boy','girl','father','mother','f','h','k']

def pres(*args):
    print("个人资料")
    return
class MyApp(App):
    def build(self):
        layout = BoxLayout(orientation="vertical")
        finerout = BoxLayout()
        people = GridLayout(cols=1, spacing=[0, 0], size_hint_max_x="200dp", padding=[1, 0, 0, 0])
        for i in people_list:
            _cat = Button(text=i,on_press=lambda e: print("开始聊天"))
            people.add_widget(_cat)
        finerout.add_widget(Image(source='image.jpg',size_hint_max_x="50dp",keep_ratio=False,allow_stretch=True))
        finerout.add_widget(people)
        finerout.add_widget(TextInput(text="WXcat"))
        self.sm = ScreenManager()
        screen = Screen(name='user')
        screen1 = Screen(name='home')
        # title_bar = BoxLayout(size_hint_max_y="100dp")
        title_bar = BoxLayout()
        title_bar1 = BoxLayout()
        # title_bar.add_widget(Button(text="user",on_press=pres))
        # title_bar.add_widget(Button(text="home",on_press=lambda e: print("微信首页")))
        main_button1 = Button(text='home')
        main_button1.bind(on_press=self.main_button1)
        main_button = Button(text='user',)
        main_button.bind(on_press=self.main_button)
        title_bar1.add_widget(main_button1)
        screen1.add_widget(title_bar1)
        self.sm.add_widget(screen1)
        title_bar.add_widget(main_button)
        screen.add_widget(title_bar)
        self.sm.add_widget(screen)
        layout.add_widget(finerout)
        layout.add_widget(self.sm)
        return layout
    def main_button(self,instance):
        self.sm.current='home'

    def main_button1(self, instance):
        self.sm.current = 'user'


if __name__ == '__main__':
    MyApp().run()